<route lang="json5">
  {
    style: {
      navigationBarTitleText: '宝豆记录',
    },
  }
  </route>
<template>
  <view class="page">





    <view class="content-card">
      <scroll-view scroll-y class="record-list" @scrolltolower="loadMore" @refresherrefresh="onRefresh"
        :refresher-enabled="true" :refresher-triggered="isRefreshing">
        <view v-if="records.length > 0">
          <view v-for="(record, index) in records" :key="index" :class="['record-card', record.type]">
            <view class="record-header">
              <text class="type-text">{{ record.type_text }}</text>
              <text :class="'amount' + record.type">{{ record.num }}</text>
            </view>
            <view class="record-info">
              <text class="id">交易ID: {{ record.sn }}</text>
              <text class="time">{{ record.createtime_str }}</text>
            </view>


          </view>
        </view>
        <view v-else class="empty-state">
          <uni-icons type="info" size="64" color="#999999" />
          <text class="empty-text">暂无积分记录</text>
        </view>
      </scroll-view>

    </view>
    <!-- 记录列表 -->

  </view>
</template>

<script lang="ts" setup>
import { ref } from 'vue'

import { getCargoValueListAPI } from '@/service/index'

const currentTab = ref(0)

const isRefreshing = ref(false)

const records = ref([])

const handleTabChange = (index: number) => {
  currentTab.value = index
  params.value.type = index
  params.value.page = 1
  getCargoValueList()
}

const handleBack = () => {
  uni.navigateBack()
}

const loadMore = () => {
  // 加载更多数据
  params.value.page++
  getCargoValueList()
}

const onRefresh = () => {
  isRefreshing.value = true
  setTimeout(() => {
    isRefreshing.value = false
  }, 1000)
}
const params = ref({
  page: 1,
  pageSize: 10,
  type: 0,
})
const getCargoValueList = () => {
  getCargoValueListAPI(params.value).then(res => {
    console.log(res)
    if (res.code === 1) {
      records.value = res.data.list
    }
  })
}

//#ifdef APP-PLUS || MP-WEIXIN
onLoad(() => {
  getCargoValueList()
})
//#endif  

//#ifdef H5
onMounted(() => {
  getCargoValueList()
})
//#endif



</script>

<style>
page {
  height: 100%;
}

.page {
  display: flex;
  flex-direction: column;
  height: 100%;
  background-color: #f5f5f5;
}

.header {
  flex-shrink: 0;
  background-color: #ffffff;
}

.content-card {
  padding: 0 20rpx;
}

.container {
  display: flex;
  flex-direction: column;
  height: 100%;
  background-color: #f5f5f5;
}



.back-icon {
  position: absolute;
  left: 30rpx;
  width: 20px;
  height: 20px;
}

.title {
  font-size: 16px;
  font-weight: 500;
  color: #333333;
}

.tabs {
  display: flex;
  border-bottom: 1px solid #eeeeee;
}

.tab-item {
  position: relative;
  flex: 1;
  height: 88rpx;
  font-size: 14px;
  line-height: 88rpx;
  color: #666666;
  text-align: center;
}

.tab-item.active {
  color: #1890ff;
}

.tab-item.active::after {
  position: absolute;
  bottom: 0;
  left: 50%;
  width: 40rpx;
  height: 4rpx;
  content: '';
  background-color: #1890ff;
  transform: translateX(-50%);
}

.record-list {
  flex: 1;
  padding: 20rpx 0;
  overflow: auto;
}

.record-card {
  padding: 30rpx;
  margin-bottom: 20rpx;
  background-color: #ffffff;
  border-radius: 12rpx;
}

.record-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20rpx;
}

.type-text {
  font-size: 16px;
  font-weight: 500;
  color: #333333;
}

.amount {
  font-size: 16px;
  font-weight: 500;
}

.amount0 {
  color: #07c160;
}

.amount1 {
  color: #ff4d4f;
}

.amount2 {
  color: #ff9500;
}

.amount.income {
  color: #07c160;
}

.amount.expense {
  color: #ff4d4f;
}

.amount.withdraw {
  color: #ff9500;
}

.record-info {
  display: flex;
  justify-content: space-between;
  margin-bottom: 16rpx;
}

.id,
.time {
  font-size: 12px;
  color: #999999;
}

.record-fee {
  font-size: 12px;
  color: #999999;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding-top: 200rpx;
}

.empty-text {
  margin-top: 20rpx;
  font-size: 14px;
  color: #999999;
}
</style>
